package org.mch.func.m_px.sorteg.handle;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import com.mch.main.common.MEnv;

public class DlgCreateNewBtnArry extends JDialog {
	private static final long serialVersionUID = -6693841155376028928L;

	private final JPanel contentPanel = new JPanel();
	private JLabel label;
	private JTextField textNumberBegin;
	private JLabel label_1;
	private JTextField textNumberEnd;
	private JLabel label_2;
	private JTextField textNumberCount;

	public DlgCreateNewBtnArry() {
		super(MEnv.MAINFRAME);
		setModal(true);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		contentPanel.add(getLabel());
		contentPanel.add(getTextNumberBegin());
		contentPanel.add(getLabel_1());
		contentPanel.add(getTextNumberEnd());
		contentPanel.add(getLabel_2());
		contentPanel.add(getTextNumberCount());
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						values = new int[3];
						values[0] = Integer.parseInt(getTextNumberBegin().getText());
						values[1] = Integer.parseInt(getTextNumberEnd().getText());
						values[2] = Integer.parseInt(getTextNumberCount().getText());
						setVisible(false);
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						values = null;
						setVisible(false);
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}

	public JLabel getLabel() {
		if (label == null) {
			label = new JLabel("数值范围：");
			label.setBounds(10, 10, 70, 15);
		}
		return label;
	}

	public JTextField getTextNumberBegin() {
		if (textNumberBegin == null) {
			textNumberBegin = new JTextField();
			textNumberBegin.setEditable(false);
			textNumberBegin.setText("1");
			textNumberBegin.setBounds(80, 7, 35, 21);
			textNumberBegin.setColumns(10);
		}
		return textNumberBegin;
	}

	public JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("——");
			label_1.setFont(new Font("宋体", Font.BOLD, 15));
			label_1.setHorizontalAlignment(SwingConstants.CENTER);
			label_1.setBounds(116, 10, 46, 15);
		}
		return label_1;
	}

	public JTextField getTextNumberEnd() {
		if (textNumberEnd == null) {
			textNumberEnd = new JTextField();
			textNumberEnd.setText("100");
			textNumberEnd.setBounds(162, 7, 46, 21);
			textNumberEnd.setColumns(10);
		}
		return textNumberEnd;
	}

	public JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("数值个数：");
			label_2.setBounds(10, 35, 70, 15);
		}
		return label_2;
	}

	public JTextField getTextNumberCount() {
		if (textNumberCount == null) {
			textNumberCount = new JTextField();
			textNumberCount.setText("10");
			textNumberCount.setBounds(80, 32, 35, 21);
			textNumberCount.setColumns(10);
		}
		return textNumberCount;
	}

	private int[] values;

	public int[] getValues() {
		return values;
	}
}
